<?php
namespace Home\Controller;
use Think\Controller;
class UserCenterController extends Controller {
    public function index(){
        //$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }

    public function test(){$token = create_guid();var_dump($token);die;
    	$data = array('name'=> 'wlg','city'=>'shenzhen');
    	echo json_encode($data);
    } 

    public function login(){
        $username = $_GET['name'];
        $password = md5($_GET['password']);
        $info = D('User')->where(array('account'=>$username))->find();
        //var_dump($password);die;
        if($info){
            if($info['password'] == $password){
                $data['code'] = '1';
                $data['msg'] = '登录成功';
                $data['info'] = $info;
                $token['id'] = M('User_token')->max('id')+1;
                $token['uid'] = $info['id'];
                $token['token'] = create_guid();
                $z = M('User_token')->add($token);
                $data['token'] = $token['token'];
            }else{
                $data['code'] = '-1';
                $data['msg'] = '密码错误';
            }
        }else{
            $data['code'] = '-2';
            $data['msg'] = '用户不存在';
        }

        kuayu();
        echo json_encode($data);
    }


    //注册-短信认证方式
    public function code(){

//        $code = $_GET['code'];
//        $tel = $_GET['tel'];
//        Vendor('Message.ChuanglanSmsApi');
//        $clapi  = new \ChuanglanSmsApi();
//        $result = $clapi->sendSMS($tel, '【253云通讯】您好，您的验证码是'.$code);
//        $result = $clapi->execResult($result);
    }


    //注册-密码方式

    public function register(){

        $data = $_POST;
        //$data = json_decode(file_get_contents('php://input'),true);
        $info = D('Users')->where('account = '.$data['account'])->find();
        if($info){
            $d['code'] = '-1';
            $d['msg'] = '用户已注册,请找回密码';
        }else{
            $data['id'] = D('Users')->max('id')+1;
            $data['password'] = md5($data['password']);
            $z = D('Users')->add($data);
            if($z){
                $d['code'] = '1';
                $d['msg'] = '注册成功';
            }else{
                $d['code'] = '-2';
                $d['msg'] = '注册失败';
            }
        }


        header('content-type:application:json;charset=utf8');
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:POST');
        header('Access-Control-Allow-Headers:x-requested-with,content-type');
        echo json_encode($d);
    }
    //注册-密码方式
    public function register1(){
    	//$args['os'] = $_POST['os'];
        //$args['uuid'] = $_POST['uuid'];
        //$args['version'] = $_POST['version'];
        $args['timestamp'] = $_POST['timestamp'];
        $signature = $_POST['signature'];
        $signtype = $_POST['signtype']; //是否开启验证
        $check = checkSign($args,$signature,$signtype);
        if(!$check)
        {
            $res['msg_code'] = 99999; //签名错误
            $res['msg_info'] = '非法访问';
            
        }else{
        	$res['msg_code'] = 0; //签名成功
        	$res['msg_info'] = '注册成功';
        }

        return json_encode($res);
    }


    //忘记密码
    public function forget_pwd(){

    }

}